package org.example;

import bean.ResponseUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

@WebServlet("/logoutServlet")
public class logoutServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取当前 session
        HttpSession session = request.getSession(false);

        // 如果 session 存在，则销毁其中的用户信息
        if (session != null) {
            session.invalidate(); // 销毁 session
        }

        // 通过 ResponseUtils 发送响应
        ResponseUtils.sendResponse(response, "已成功退出登录", "login.jsp"); // 跳转到 login.jsp 页面
    }
}
